package composite

import (
	"fmt"
)

type MenuComponent interface {
	MenuPrint()
}

type Menu struct {
	name          string
	description   string
	menuComponent []MenuComponent
}

func NewMenu(n string, d string) *Menu {
	r := new(Menu)
	r.name = n
	r.description = d

	return r
}

func (c *Menu) Add(m MenuComponent) {
	c.menuComponent = append(c.menuComponent, m)
}

func (c *Menu) GetName() string {
	return c.name
}

func (c *Menu) GetDescription() string {
	return c.description
}

func (c *Menu) MenuPrint() {
	fmt.Println(c.name)
	fmt.Println(c.description)
	fmt.Println("-------------------------------")
	for i, _ := range c.menuComponent {
		c.menuComponent[i].MenuPrint()
	}
}

type MenuItem struct {
	name        string
	description string
	vegetarian  bool
	price       float32
}

func NewMenuItem(n string, d string, v bool, p float32) *MenuItem {
	r := new(MenuItem)
	r.name = n
	r.description = d
	r.vegetarian = v
	r.price = p

	return r
}

func (c *MenuItem) getName() string {
	return c.name
}

func (c *MenuItem) getDescription() string {
	return c.description
}

func (c *MenuItem) getPrice() float32 {
	return c.price
}

func (c *MenuItem) isVegetarian() bool {
	return c.vegetarian
}

func (c *MenuItem) MenuPrint() {
	fmt.Println(c.name)
	if c.vegetarian {
		fmt.Println("(v)")
	}
	fmt.Println(c.price)
	fmt.Println(c.description)
}

//////////////////////////////////////////////////////////
type Waitress struct {
	allMenus MenuComponent
}

func NewWaitress(a MenuComponent) *Waitress {
	r := new(Waitress)
	r.allMenus = a

	return r
}

func (c *Waitress) PrintMenu() {
	c.allMenus.MenuPrint()
}
